﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// BasePage 所有页面的基类 
/// </summary>
public class BasePage:System.Web.UI.Page
{
    #region 属性
    /// <summary>
    /// 返回虚拟目录路径
    /// </summary>
    public string ApplicationPath
    {
        get
        {
            string applicationPath = HttpContext.Current.Request.ApplicationPath;
            if (applicationPath == "/")
            {
                return string.Empty;
            }
            else
            {
                return applicationPath;
            }
        }
    }
    /// <summary>
    /// 所有录入数据模块的流水号
    /// </summary>
    protected string BillNo
    {
        get
        {
            if (ViewState["SBillNo"] == null) return "";
            return (string)ViewState["SBillNo"];
        }
        set
        {
            ViewState["SBillNo"] = value;
        }
    }

    

    #region 权限属性

    /// <summary>
    /// 模块编号
    /// </summary>
    protected virtual string ModuleID
    {
        get
        {
            return Request["ModuleNo"];
        }
    }

    /// <summary>
    /// 模块名称
    /// </summary>
    protected virtual string ModuleName
    {
        get
        {
            return string.Empty;
        }
    }

    /// <summary>
    /// 是否可以新增、编辑、删除
    /// </summary>
    protected bool CanEditData
    {
        get
        {
            return true;// PermissionModules.Contains(ModuleID + "01");
        }
    }
   

    /// <summary>
    /// 是否可以查看所有数据
    /// </summary>
    protected bool CanBrowsAll
    {
        get
        {
            return PermissionModules.Contains(ModuleID + "05");
        }
    }

    /// <summary>
    /// 是否可以浏览
    /// </summary>
    protected bool CanBrows
    {
        get
        {
            return false;
        }
    }
    /// <summary>
    /// 用户可操作的模块列表
    /// </summary>
    protected ArrayList PermissionModules
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).Permits;
        }
    }


    #endregion

    #region 用户属性

    ///// <summary>
    ///// 用户帐号
    ///// </summary>
    //public string UserID
    //{
    //    get
    //    {
    //        return Context.User.Identity.Name;
    //    }
    //}

    /// <summary>
    /// 用户编码
    /// </summary>
    public string UserCode
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).UserCode;
        }
    }
    /// <summary>
    /// 用户姓名
    /// </summary>
    public string UserName
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).UserName;
        }
    }

    /// <summary>
    /// 用户性别
    /// </summary>
    public string Gender
    {
        get { return ((ASERIdentity)Context.User.Identity).Gender; }
    }


    /// <summary>
    /// 机构编码
    /// </summary>
    public string OrgCode
    {
        get { return ((ASERIdentity)Context.User.Identity).OrgCode; }
    }

    /// <summary>
    /// 类型编码
    /// </summary>
    public string TypeCode
    {
        get { return ((ASERIdentity)Context.User.Identity).TypeCode; }
    }

    /// <summary>
    /// 身份证号
    /// </summary>
    public string PID
    {
        get { return ((ASERIdentity)Context.User.Identity).PID; }
    }

    /// <summary>
    /// 办公电话
    /// </summary>
    public string Tel
    {
        get { return ((ASERIdentity)Context.User.Identity).Tel; }
    }

    /// <summary>
    /// 手机号码
    /// </summary>
    public string MobileNo
    {
        get { return ((ASERIdentity)Context.User.Identity).MobileNo; }
    }


    /// <summary>
    /// 用户地址
    /// </summary>
    public string Address
    {
        get { return ((ASERIdentity)Context.User.Identity).Address; }
    }

    /// <summary>
    /// 邮政编码
    /// </summary>
    public string ZipCode
    {
        get
        { return ((ASERIdentity)Context.User.Identity).ZipCode; }
    }

    /// <summary>
    /// 注册时间
    /// </summary>
    public DateTime RegDate
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).RegDate;
        }
    }

    /// <summary>
    /// 是否已更改密码
    /// </summary>
    public string IsChangePwd
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).IsChangePwd;
        }
    }

    /// <summary>
    /// 是否禁用
    /// </summary>
    public string IsForbid
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).IsForbid;
        }
    }

    /// <summary>
    /// 用户邮箱
    /// </summary>
    public string Email
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).Email;
        }

    }
    #endregion

    #endregion

    #region 重写方法

    protected override void OnLoad(EventArgs e)
    {
        if (!Request.IsAuthenticated)
        {
            string URL = ApplicationPath + "/Login.aspx";
            Response.Redirect(URL);
            return;
        }        
        
        //if (!CanBrows)
        //{
        //    string URL = ApplicationPath + "/NoPermit.htm";
        //    Response.Redirect(URL);
        //    return;
        //}        
        //ScriptManager.RegisterStartupScript
        ScriptManager.RegisterStartupScript(this, GetType(), "InitialInput", "InitialInput();", true);
        base.OnLoad(e);
    }

    #endregion

    #region 虚方法

    protected void ShowMessage(string message)
    {
        ScriptManager.RegisterClientScriptBlock(this, GetType(), "Information", "alert('" + message + "')", true);
    }

    #endregion

    
}
